package com.yuanrui.yrclub.oss.config;

import com.yuanrui.yrclub.oss.service.StorageAdapter;
import com.yuanrui.yrclub.oss.service.impl.AliStorageAdapterImpl;
import com.yuanrui.yrclub.oss.service.impl.MinioStorageAdapterImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 存储配置
 */
@Configuration
@RefreshScope
public class StorageConfig {

    @Value("${storage.type}")
    private String storageType;

    //存放所有的存储适配器

    @Bean
    @RefreshScope
    public StorageAdapter getStorageService() {
        if ("minio".equals(storageType)) {
            return new MinioStorageAdapterImpl();
        } else if ("aliyun".equals(storageType)) {
            System.out.println("aliyun");
            return new AliStorageAdapterImpl();
        }else {
            throw new IllegalArgumentException("不支持的存储类型");
        }
    }

}
